<template>
  <div class="index">
    <!-- 顶部 -->
    <div class="top"><Admin></Admin></div>
    <!-- bottom -->
    <div class="bottom">
      <div class="left"><SideNav></SideNav></div>
      <div class="right">
        <div class="content">
          <el-scrollbar style="height: 100%;">
            <!-- 当前位置 -->
            <div class="current_position">
              <p class="breadcrumb">当前位置 :</p>
              <el-breadcrumb separator="/">
                <el-breadcrumb-item class="up">生活服务</el-breadcrumb-item>
                <el-breadcrumb-item>用户列表</el-breadcrumb-item>
              </el-breadcrumb>
            </div>
            <!-- 列表 -->
            <div class="userlist">
              <div class="status_box">
                <div class="input">
                  <el-input v-model="key" placeholder="姓名 手机号" clearable></el-input>
                </div>
                <div class="search"><el-button @click="findList()">搜索</el-button></div>
              </div>
              <div class="table">
                <el-table ref="multipleTable" :data="tableData" border tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
                  <el-table-column type="selection" fixed="left" width="50"></el-table-column>
                  <el-table-column prop="id" label="用户ID" width="100"></el-table-column>
                  <el-table-column prop="wechatNickname" label="姓名"></el-table-column>
                  <el-table-column prop="phoneNumber" label="手机号"></el-table-column>
                  <el-table-column prop="authentication" label="用户认证" align="center">
                    <template slot-scope="scope">
                      <span v-if="scope.row.authentication== 1" class="userStatus1">已认证</span>
                      <span v-if="scope.row.authentication== 2" class="userStatus2">未认证</span>
                    </template>
                  </el-table-column>
                  <el-table-column prop="userCreateTime" label="注册时间"></el-table-column>
                  <el-table-column label="操作" fixed="right"  width="100">
                    <template slot-scope="scope">
                      <el-button @click="redact(scope.row)" type="text" size="small">编辑</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <el-pagination
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="currentPage"
                  :page-sizes="[10,20,30,40,50]"
                  :page-size="pageSize"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="total">
                </el-pagination>
              </div>
            </div>
          </el-scrollbar>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  let moment = require("moment")
  import Admin from '@/components/Admin.vue'
  import SideNav from '@/components/SideNav.vue'

  export default {
    name: 'UserList',
    components:{
      Admin,
      SideNav
    },
    data () {
      return {
        page: 1,//页码
        pageSize: 50,//每页条数
        total: 0,/* 总的条数 */
        currentPage: 0,/* 前往第几页 */
        tableData: [],// 表格
        multipleSelection: [], // 选择后的列表
        key:'',//搜索内容
      }
    },
    mounted() {
      this.findList();
    },
    methods: {
      // 时间格式过滤
      dateForma(row,column){
        var date = row[column.property];
        if(date == undefined){
          return ''
        }
        return moment(date).format("YYYY-MM-DD HH:mm:ss")
      },
      // 获取所有用户
      findList(){
        this.$axios.post(this.baseURL1+'admin/user/list',{
          "page":this.page,
          "size":this.pageSize,
          'key':this.key,
          "requestSource":"PC"
        }).then((res)=>{
          console.log(res,"所有用户");
          if(res.data.code==1){
            this.tableData = res.data.data.records;
            this.total = res.data.data.total;
          }
        }).catch((err)=>{
          console.log('request fail', err);
        })
      },
      // 表格的全选
      handleSelectionChange(val) {
        console.log(val);
        this.multipleSelection = val;
      },
      // 选择的每页条数
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pageSize = val;
        this.findList();
      },
      // 当前页面
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.page = val;
        this.findList();
      },
      //编辑用户
      redact(row){
        var data = row;
        this.$router.push({
          path: '/UserListDetail1',
          query: {
            data: data,
          }
        })
      },

    },
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
  @import '@/assets/css/index.scss'; //这个分号一定要写，要不会报错
  @import '@/assets/css/user.scss'; //这个分号一定要写，要不会报错
  .input{
    width: 200px;
    height: 35px;
    line-height: 35px;
  }
  >>> input{
    padding: 0 10px;
    height: 35px;
    line-height: 35px;
  }
</style>
